import request from '@/utils/request'
import qs from 'qs';
// 查询评价体系列表
export function listSystem(query) {
  return request({
    url: '/system/system/list',
    method: 'get',
    params: query
  })
}

// 查询【请填写功能名称】详细
export function getSystem(id) {
  return request({
    url: '/system/system/' + id,
    method: 'get'
  })
}

// 新增【请填写功能名称】
export function addSystem(data) {
  return request({
    url: '/system/system',
    method: 'post',
    data: data
  })
}

// 修改【请填写功能名称】
export function updateSystem(data) {
  return request({
    url: '/system/system',
    method: 'put',
    data: data
  })
}

// 删除【请填写功能名称】
export function delSystem(ids) {
  return request({
    url: '/system/system/' + ids,
    method: 'delete'
  })
}
export function getSystemChildren(id){
  return request({
    url: '/system/system/'+id+'/indicatorTree',
    method: 'get'
  })
}
export function addIndicatorSystem(data){
  return request({
    url: '/system/system/addIndicatorSystem',
    method: 'post',
    data: data
  })
}

export function search(name, startTime, endTime) {
  const params = {
    name: name || null,
    startTime: startTime || null,
    endTime: endTime || null,
  };

  const filteredParams = Object.entries(params).reduce((acc, [key, value]) => {
    if (value !== null) acc[key] = value;
    return acc;
  }, {});

  const queryString = qs.stringify(filteredParams, { encodeValuesOnly: true });

  const url = `/system/system/search?${queryString}`;

  return request({
    url,
    method: 'get',
  });
}

export function getIndicatorBySystemIdAndIndicatorId(systemId, indicatorId){
  const params = {
    systemId: systemId || null,
    indicatorId: indicatorId || null,
  };

  const filteredParams = Object.entries(params).reduce((acc, [key, value]) => {
    if (value !== null) acc[key] = value;
    return acc;
  }, {});

  const queryString = qs.stringify(filteredParams, { encodeValuesOnly: true });

  const url = `/system/system/getIndicatorBySystemIdAndIndicatorId?${queryString}`;

  return request({
    url,
    method: 'get',
  });
}


